﻿using System;
using System.Collections.Generic;
using System.Configuration;
using Controllers;

namespace Web
{
    public partial class ExamStat : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string typeId = Request.QueryString["typeId"];
            ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
            IEnumerable<ResultDTO> list = ctx.ExecuteQuery<ResultDTO>(string.Format(@"select Name,Score from
(select EmpId,SUM(Score) Score from(
SELECT b.EmpId,a.Id,QuestionType,a.Answer,b.Answer bAnswer,
      case when a.Answer=b.Answer and a.QuestionType='判断题' then 0.5
      when a.Answer=b.Answer and a.QuestionType='单项选择题' then 2
      when a.Answer=b.Answer and a.QuestionType='不定项选择题' then 3 else 0 end Score
  FROM ExamQuestions a inner join ExamAnswers b on a.Id=b.QuestionId
  where a.TypeId={0}) t
  group by EmpId) t2 inner join Employee c on t2.EmpId=c.Id
  order by Name;", typeId));
            rptList.DataSource = list;
            rptList.DataBind();
        }
    }
}